﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    public class DataBaseHelper
    {
        private readonly string sqlCommandString= "select*from Table_1";
        private readonly string connectionString = "server=.;database=biao;uid=sa;pwd=1632174115";

        public static void PrintUserInfo()
        {
            string connectionString = "server=.;database=biao;uid=sa;pwd=1632174115";
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            var sqlCommandString = "select*from Table_1";
            SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);
            var sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}", sqlDataReader["id"], sqlDataReader["money"], sqlDataReader["ordernumber"]);

            }
            sqlConnection.Close();

        }
        public void PrintUserInfoAdaper()
        {
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommandString, connectionString);
            
            DataTable dataTable = new DataTable();
            dataAdapter.Fill(dataTable);
            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine("{0}\t{1}\t{2}\t{3}\t", "Id", "用户名", "密码", "创建时间");
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}\t", dataTable.Rows[i]["Id"], dataTable.Rows[i]["Username"], dataTable.Rows[i]["password"], dataTable.Rows[i]["Cr"]);

            }
        }
    }
}
